/**
 * 
 */
package org.swing.utility.system.conts;

/**
 * @author lqnhu
 *
 */
public class CaseInsensitiveString {
	private final String key;
	private String lower;

	public CaseInsensitiveString(String key) {
		this.key = key;
		this.lower = key.toLowerCase();
	}

	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((key == null) ? 0 : lower.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CaseInsensitiveString other = (CaseInsensitiveString) obj;
		if (key == null) {
			if (other.key != null)
				return false;
		} else if (!lower.equals(other.lower))
			return false;
		return true;
	}

	public String toString() {
		return this.key;
	}

	public boolean isNull() {
		return this.key == null;
	}
}
